package com.xzakota.minesweeper.model.entity;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

/**
 * 游戏难度实体类
 *
 * @author Xzakota
 */
public class LevelBean implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    public static final int ID_CUSTOM = 0;
    public static final int ID_BASIC = 1;
    public static final int ID_INTERMEDIATE = 2;
    public static final int ID_EXPENSE = 3;

    public static final LevelBean LEVEL_BASIC = new LevelBean(LevelBean.ID_BASIC, "初级", 10, 9, 9);
    public static final LevelBean LEVEL_INTERMEDIATE = new LevelBean(LevelBean.ID_INTERMEDIATE, "中级",
            40, 16, 16);
    public static final LevelBean LEVEL_EXPENSE = new LevelBean(LevelBean.ID_EXPENSE, "高级", 99, 36, 16);
    public static final LevelBean LEVEL_CUSTOM = new LevelBean(LevelBean.ID_CUSTOM, "自定义", 40, 16, 16);

    public static final int MAX_X = 30;
    public static final int MAX_Y = 24;
    public static final int MAX_AMOUNT = 668;
    public static final int MIN_X = 9;
    public static final int MIN_Y = 9;
    public static final int MIN_AMOUNT = 10;

    public int mineAmount;
    public int maxX;
    public int maxY;
    public int id;
    public String name;

    public LevelBean() {
        this.name = null;
    }

    public LevelBean(int id, String name, int mineAmount, int maxX, int maxY) {
        this.mineAmount = mineAmount;
        this.maxX = maxX;
        this.maxY = maxY;
        this.id = id;
        this.name = name;
    }

    public static LevelBean getGameLevelByID(int id) {
        return switch (id) {
            case LevelBean.ID_BASIC -> LevelBean.LEVEL_BASIC;
            case LevelBean.ID_INTERMEDIATE -> LevelBean.LEVEL_INTERMEDIATE;
            case LevelBean.ID_EXPENSE -> LevelBean.LEVEL_EXPENSE;
            default -> LevelBean.LEVEL_CUSTOM;
        };
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        LevelBean levelBean = (LevelBean) o;
        return mineAmount == levelBean.mineAmount && maxX == levelBean.maxX && maxY == levelBean.maxY && id == levelBean.id && Objects.equals(name, levelBean.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mineAmount, maxX, maxY, id, name);
    }

    @Override
    public String toString() {
        return "LevelBean{" +
                "mineAmount=" + mineAmount +
                ", maxX=" + maxX +
                ", maxY=" + maxY +
                ", id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
